package com.sharkburner.aeris.ui.module.site.model;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sharkburner.aeris.dao.entity.Site;
import com.sharkburner.aeris.service.source.SourceService;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Label;
import com.vaadin.ui.themes.Reindeer;

/**
 * @author ArtyomyuS
 * 
 */
@Component
public class SourceListModel implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	private SourceService sourceService;
	private static final String PROPERTY_CHECKBOX = " ";
	private static final String PROPERTY_SOURCE = "SOURCE";
	private static final String PROPERTY_OPTIONS = "  ";

	private static final String ACTION = "Delete";

	/**
	 * @return
	 */
	public Container getData() {
		IndexedContainer container = new IndexedContainer();
		List<Site> sources = sourceService.findSources();

		container.addContainerProperty(PROPERTY_CHECKBOX, CheckBox.class, new CheckBox());
		container.addContainerProperty(PROPERTY_SOURCE, String.class, "");
		container.addContainerProperty(PROPERTY_OPTIONS, Label.class, new Label());

		for (Site source : sources) {
			Item item = container.addItem(source.getId());
			item.getItemProperty(PROPERTY_CHECKBOX).setValue(new CheckBox());
			item.getItemProperty(PROPERTY_SOURCE).setValue(source.getName());
			
			Label action = new Label(ACTION);
			action.setStyleName(Reindeer.LABEL_SMALL);
			item.getItemProperty(PROPERTY_OPTIONS).setValue(action);
		}

		return container;
	}

}
